/**
 * 账户和美食的有关图片上传的js文件，千万别误删了！！！！
 */
(function($, undefined) {
	// 图片上传 logo 图
	function onCoverPicUploadStart() {
		$('#backgroundPicLogo').uploadifySettings('scriptData', {
			'imgHeight' : 128,
			'imgWidth' : 128,
			'fixName' : '*.jpeg;*.jpg;*.png',
			'imgType' : 1
		});
	}

	function onCoverImageUploadStart() {
		$('#imageUpLoad').uploadifySettings('scriptData', {
			'imgHeight' : 128,
			'imgWidth' : 128,
			'fixName' : '*.jpeg;*.jpg;*.png',
			'imgType' : 1
		});
	}

	function onCoverImageUploadSuccess(event, queueID, fileObj, response) {
		var res = JSON.parse(response);
		if (res.result == 'ok') {
			$('#image').attr("src", res.picSavePath);
			console.log(res.picSavePath);
			$("#image").siblings().css("display", "inline");
			$('#imagePath').attr("value", res.picSavePath);
			console.log(res.picId);
			$("#imageId").attr("value", res.picId);
			$('#image').attr("style", "width:100px;height:100px;");
			console.log(res.picSavePath);
		}
	}

	function onCoverPicUploadSuccess(event, queueID, fileObj, response) {
		var res = JSON.parse(response);
		if (res.result == 'ok') {
			$('#backgroundPicPathLogo').attr("src", res.picSavePath);
			$("#backgroundPicPathLogo").siblings().css("display", "inline");
			$('#picPath').attr("value", res.picSavePath);
			$("#avatarId").attr("value", res.picId);
			$('#backgroundPicPathLogo').attr("style",
					"width:100px;height:100px;");
		}
	}

	$(function() {
		var topPic = $('#picPath').val();
		if (topPic) {
			$('#imageOneShow').attr("src", topPic);
		}

		var image = $('#imagePath').val();
		if (image) {
			$('#image').attr("src", image);
		}

		$.mitian.initSingleFileUploader('#backgroundPicLogo',
				"*.jpeg;*.jpg;*.png", 1024 * 1024, onCoverPicUploadStart,
				onCoverPicUploadSuccess);

		$.mitian
				.initSingleFileUploader('#imageUpLoad', "*.jpeg;*.jpg;*.png",
						1024 * 1024, onCoverImageUploadStart,
						onCoverImageUploadSuccess);
		
	});
})(jQuery);